<xsl:stylesheet version="2.0" 
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
		xmlns="http://www.w3.org/1999/xhtml">
		
		<xsl:template match="forest">
			<html>
				<head>
					<title>Evolving Intelligence - Generation Forest</title>
					<style type="text/css">
						body {font-family:Century Gothic;}
						p {margin:10px;}
					</style>
				</head>
				<body>
					<h1>Generation <xsl:value-of select="@generation"/></h1>
					<xsl:apply-templates select="tree"/>
				</body>
			</html>
		</xsl:template>
		
		<xsl:template match="tree">
        	<h3><xsl:value-of select="number(@place) + 1"/>. Tree (<xsl:value-of select="@score"/>)</h3>
        	<xsl:apply-templates/>
		</xsl:template>
        
        <xsl:template match="const">
        	<xsl:call-template name="indent">
            	<xsl:with-param name="count" select="count(ancestor::*) - 2"/>
            </xsl:call-template> 
            
        	<xsl:value-of select="@value"/> <br/>
		</xsl:template>

		<xsl:template match="func">
        	<xsl:call-template name="indent">
            	<xsl:with-param name="count" select="count(ancestor::*) - 2"/>
            </xsl:call-template> 
        	
        	<xsl:value-of select="@name"/> <br/>
            <xsl:apply-templates/>
		</xsl:template>

		<xsl:template match="param">
        	<xsl:call-template name="indent">
            	<xsl:with-param name="count" select="count(ancestor::*) - 2"/>
            </xsl:call-template>
            
        	p<xsl:value-of select="@index"/> <br/>
		</xsl:template>
        
        <xsl:template name="indent">
        	<xsl:param name="count" select="0"/>
            
            <xsl:if test="number($count) > 0">
                <xsl:choose>
                	<xsl:when test="number($count) > 1">
                		<xsl:text>| </xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                    	<xsl:text>| - </xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:call-template name="indent">
                    <xsl:with-param name="count" select="number($count) - 1"/>
                </xsl:call-template>
            </xsl:if>
		</xsl:template>
</xsl:stylesheet>